#pragma once

#ifndef max
#define max(a, b) ((a) > (b) ? (a) : (b))
#endif
#ifndef min
#define min(a, b) ((a) < (b) ? (a) : (b))
#endif
#ifndef bound
#define bound(x, low, high)                                                    \
  ((x) < (low) ? (low) : ((x) > (high) ? (high) : (x)))
#endif
// module switch
// comment the module if you don't want to use
#define CUSTOM_PWM_ENABLED 1
#define LCD_MODULE_ENABLED 1
// #define DOWNCOUNTER_MODULE_ENABLED 1

#define USE_FULL_ASSERT 1

// #define TEST_MOTOR
// #define TEST_PID

#define SEARCH_DETECT_COLOR 0 // 1: black, 0: white, provided by interface.h

// TIMER related
#define SYSTEM_CORE_CLK 72000000 // 系统时钟设置为72MHz
#define TIM_DEFAULT_SCALE 72     // 72分频
#define TIM_DEFAULT_CLK                                                        \
  (SYSTEM_CORE_CLK / TIM_DEFAULT_SCALE) // TIM时钟默认设置为1MHz
#define TIM_DEFAULT_PERIOD_us                                                  \
  (1000000 / TIM_DEFAULT_CLK) // TIM时钟默认周期为1us

#ifdef CUSTOM_PWM_ENABLED
// Motor related GPIO
#include "stm32f10x.h"
#define MOTOR_GPIO_PORT_L_SIDE_POSITIVE GPIOD
#define MOTOR_GPIO_PIN_L_SIDE_POSITIVE GPIO_Pin_6
#define MOTOR_GPIO_PORT_R_SIDE_POSITIVE GPIOC
#define MOTOR_GPIO_PIN_R_SIDE_POSITIVE GPIO_Pin_11
#define MOTOR_GPIO_PORT_L_SIDE_NEGATIVE GPIOG
#define MOTOR_GPIO_PIN_L_SIDE_NEGATIVE GPIO_Pin_9
#define MOTOR_GPIO_PORT_R_SIDE_NEGATIVE GPIOD
#define MOTOR_GPIO_PIN_R_SIDE_NEGATIVE GPIO_Pin_0
#endif

#ifdef CUSTOM_LRC_SEARCH_ENABLED
// LRC search related GPIO
#include "stm32f10x.h"
#define LRC_SEARCH_GPIO_PORT_L GPIOG
#define LRC_SEARCH_GPIO_PIN_L GPIO_Pin_4
#define LRC_SEARCH_GPIO_PORT_R GPIOG
#define LRC_SEARCH_GPIO_PIN_R GPIO_Pin_6
#define LRC_SEARCH_GPIO_PORT_C GPIOG
#define LRC_SEARCH_GPIO_PIN_C GPIO_Pin_8
#endif